﻿Chenxin.UI.StructComboList=Chenxin.extend(null,{
	tbxWidth:45,
	comboContainerId:{
		city:'#city',
		company:'#company',
		businessDistrict:'#businessdistrict',
		departs:'#departs',
		employee:'#employee'
	},
	/**
	*@description 城市选中之后的时间，默认传递选中的新值
	*/
	cityAfterSelected:Chenxin.emptyFn,
	
	/**
	*@description 公司选中之后的时间，默认传递选中的新值
	*/
	companyAfterSelected:Chenxin.emptyFn,
	/**
	*@description 商圈选中之后的时间，默认传递选中的新值
	*/
	businessDistrictAfterSelected:Chenxin.emptyFn,
	/**
	*@description 门店选中之后的时间，默认传递选中的新值
	*/
	departsAfterSelected:Chenxin.emptyFn,
	
	/**
	*@description 城市Item加载之后,默认传递Items数组
	*/
	cityAfterLoadItem:Chenxin.emptyFn,
	
	/**
	*@description 公司Items加载之后,默认传递Items数组
	*/
	companyAfterLoadItem:Chenxin.emptyFn,
	comboNameConfig:{},
	createComboList:function(){		
		var _this=this;
		//城市
		this.city=new Chenxin.UI.StructCombo({
			param:{op:'getcity'},
			containerId:this.comboContainerId.city,
			name:this.comboNameConfig.city,
			tbxWidth:this.tbxWidth,
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					this.initValue=this.items[0].val;
					_this.company.param.fatherid=this.items[0].val;
					_this.company.reload();
				}else{
					this.addPleaseSelected=true;			
				}
				
				if(_this.cityAfterLoadItem){
					_this.cityAfterLoadItem.call(_this,this.items);
				}
			},
			onSelected:function(){
				if(this.getValue()==this.defVal){
					_this.company.clearItems();
				}else{
					_this.company.param.fatherid=this.getValue();
					_this.company.reload();
				}
				_this.businessDistrict.clearItems();
				_this.departs.clearItems();
				_this.emp.clearItems();
				
				if(_this.cityAfterSelected){
					_this.cityAfterSelected.call(_this,this.getValue());
				}
			}
		});
		
		//公司
		this.company=new Chenxin.UI.StructCombo({
			autoLoad:false,
			param:{op:'getcompany'},
			tbxWidth:this.tbxWidth,
			name:this.comboNameConfig.company,
			containerId:this.comboContainerId.company,
			afterLoadItems:function(){
				if(this.items.length==1){
					this.addPleaseSelected=false;
					this.initValue=this.items[0].val;
					_this.businessDistrict.param.fatherid=this.items[0].val;
					_this.businessDistrict.reload();
				}else{
					this.addPleaseSelected=true;					
				}
				if(_this.companyAfterLoadItem){
					_this.companyAfterLoadItem.call(_this,this.items);
				}
			},
			onSelected:function(){
				if(this.getValue()==this.defVal){
					_this.businessDistrict.clearItems();
				}else{
					_this.businessDistrict.param.fatherid=this.getValue();
					_this.businessDistrict.reload();
				}
				_this.departs.clearItems();
				_this.emp.clearItems();
				if(_this.companyAfterSelected){
					_this.companyAfterSelected.call(_this,this.getValue());
				}
			}
		});
		
		//商圈
		this.businessDistrict=new Chenxin.UI.StructCombo({
			autoLoad:false,
			param:{op:'getbusinessdistrict'},
			tbxWidth:this.tbxWidth,
			colWidth:90,
			colNum:4,
			name:this.comboNameConfig.businessDistrict,
			containerId:this.comboContainerId.businessDistrict,
			onSelected:function(){
				if(this.getValue()==this.defVal){
					_this.departs.clearItems();
				}else{
					_this.departs.param.fatherid=this.getValue();
					_this.departs.reload();
				}
				_this.emp.clearItems();
				if(_this.businessDistrictAfterSelected){
					_this.businessDistrictAfterSelected.call(_this,this.getValue());
				}
			}
		});
		//门店
		this.departs=new Chenxin.UI.StructCombo({
			autoLoad:false,
			name:this.comboNameConfig.departs,
			tbxWidth:this.tbxWidth,
			colNum:3,
			colWidth:90,
			containerId:this.comboContainerId.departs,
			param:{op:'getdeparts'},
			onSelected:function(){
				if(this.getValue()==this.defVal){
					_this.emp.clearItems();
				}else{
					_this.emp.param.fatherid=this.getValue();
					_this.emp.reload();
				}
				if(_this.departsAfterSelected){
					_this.departsAfterSelected.call(_this,this.getValue());
				}
			}
		});
		//人
		this.emp=new Chenxin.UI.StructCombo({
			autoLoad:false,
			tbxWidth:this.tbxWidth,
			colNum:2,
			colWidth:100,
			name:this.comboNameConfig.employee,
			containerId:this.comboContainerId.employee,
			param:{op:'getemployee'}
		});
		
		return [this.city,this.company,this.businessDistrict,this.departs,this.emp];
	},
	initComponent:function(){
		Chenxin.applyIf(this.comboNameConfig,{
			city:'cityid',
			company:'companyid',
			businessDistrict:'areaid',
			departs:'departid',
			employee:'userid'
		});
		this.comboList=this.createComboList();
	}
});